package net.togogo.metaObjectHandler;

import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

//公共字段填充处理器
public class MyMetaHandler extends MetaObjectHandler {

    //插入操作自动填充
    @Override
    public void insertFill(MetaObject metaObject) {
        //获取到需要被填充字段的值
        Object fieldValue = getFieldValByName("lastname", metaObject);
        if (fieldValue == null){
            System.out.println("======插入操作，满足填充条件======");
            setFieldValByName("lastname","钱多多",metaObject);
        }
    }

    //修改操作自动填充
    @Override
    public void updateFill(MetaObject metaObject) {
        //获取到需要被填充字段的值
        Object fieldValue = getFieldValByName("lastname", metaObject);
        if (fieldValue == null){
            System.out.println("======修改操作，满足填充条件======");
            setFieldValByName("lastname","钱太多",metaObject);
        }
    }
}
